package com.ruitu.health_1.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.viewpager.widget.PagerAdapter;

import com.bumptech.glide.Glide;
import com.ruitu.health_1.R;

import java.util.List;

import uk.co.senab.photoview.PhotoView;

/**
 * Created by Administrator on 2018/2/28 0028.
 */

public class ViewPagerAdapter extends PagerAdapter {

    private Context context;
    private List<String> mList;

    public ViewPagerAdapter(Context context , List<String> list){
        this.context = context;
        this.mList =list;
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View itemView = getItemView(R.layout.view_pager_img);
        PhotoView image = (PhotoView) itemView.findViewById(R.id.image);

        Glide.with(context).load(mList.get(position)).into(image);
        container.addView(itemView);
        return itemView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    private View getItemView(int view_pager_img) {
        View view = LayoutInflater.from(this.context).inflate(view_pager_img ,null ,false);
        return view;
    }
}
